package com.employee.crud.controller;

import com.employee.crud.Employee;
import com.employee.crud.EmployeeRepository;
import com.employee.crud.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    private final EmployeeRepository employeeRepository;

    @Autowired
    public EmployeeController(EmployeeRepository employeeRepository) {

        this.employeeRepository = employeeRepository;
    }
    @GetMapping("employees")
    public List<Employee> getAllUser() {
        return employeeService.findAll();
    }
    @DeleteMapping("delete")
    public void   delete(int id){
        employeeService.deleteUser(id);
    }
    @GetMapping("insert")
    public String insert(int id,String name,int age,String gender){
        if (employeeRepository.insert(id,name,age,gender)>0){
            return "添加成功";
        };
        return "添加失败";
    }
    @GetMapping("update")
    public String update(String name,int age,String gender,int id){
        if (employeeService.update(name,age,gender,id)>0){
            return "修改成功";
        }
        return "修改失败";
    }
}
